<template>
  <DataList 
  :cate="cate"
  :cols="cols"
  ref="datalist"
  :groupCheck = "groupCheck" 

  :excelHeader="excelHeader"
  skipExcelNumber="3"
  :name="name"/>
</template>
<script>
import DataList from "@/components/DataList";
import { getUser } from "@/utils/auth";
import { get教师基本情况ByGH,get教师基本情况 } from "@/api/教师基本情况";
import {get教师其他情况FByGH,get教师其他情况F} from "@/api/教师其他情况"
import linq from "linq";
import { addJxyjjbqk, deleteJxyjjbqk, updateJxyjjbqk, getJxyjjbqk, bulkAddJxyjjbqk } from "@/api/专职教学研究人员情况.js";
import { mkdir } from 'fs';
import {findComponent} from "@/utils/ui";
export default {
  components: {
    DataList
  },
  data() {
    return {
      cate: "A8-6专职教学研究人员基本情况表",
      name:'8.6 专职教学研究人员情况',
      excelHeader:{B3:"教工号",C3:"姓名",D3:"是否在编",E3:"教研成果",E4:"数量（项）",F4:"最高等级",G4:"合作情况"},
      cols: [
     
        { label: "教工号", prop: "GH" },
        { label: "姓名", prop: "XM" },
        { label: "是否在编", prop: "XZ_SFZB" },
        { label: "性别", prop: "XZ_XB" },
        { label: "出生日期", prop: "CSRQ" },
        { label: "民族", prop: "XZ_MZ" },
        { label: "学历", prop: "XZ_XL" },
        { label: "学位", prop: "XZ_XW" },
        { label: "专业领域", prop: "XZ_ZYLY"},
        {
          label: "专业技术职务(最高)",
          data: [
            { label: "等级", prop: "XZ_ZYJSZW_DJ" },
            { label: "名称", prop: "ZYJSZW_MC" },
            { label: "发证单位", prop: "ZYJSZW_FZDW" },
            { label: "获取日期(年月)", prop: "ZYJSZW_HQRQ" }
          ]},
       {
           label: "在研课题",
           data: [
               { label: "课题性质", prop: "XZ_ZYKT_KTXZ" },
               { label: "课题分类", prop: "XZ_KTFL" },
               { label: "课题名称", prop: "ZYKT_KTMC" },
               { label: "是否横向课题", prop: "XZ_SFHXKT" },
               { label: "课程级别", prop: "XZ_ZYKT_KTJB" },
               { label: "立定日期", prop: "ZYKT_LXRQ" },
               { label: "经费来源", prop: "ZYKT_JFLY" },
               { label: "到款金额(元)", prop: "ZYKT_DKJE" },
               { label: "完成人顺序", prop: "XZ_ZYKT_WCRSX" },
           ]},
           {
               label: "教研成果",
               data: [
                   { label: "数量(顶)", prop: "JYCG_SL"},
                   { label: "最高等级", prop: "JYCG_DJ"},
                   { label: "合作情况", prop: "XZ_JYCG_HZQK"},
               ]
           }
        
      ],
      groupCheck:[{dada:["JYCG_SL","JYCG_DJ","XZ_JYCG_HZQK"],desc:'请完善教研成果的输入'}]
    };
  },
   methods: {
     getSummaries(list){
      //
        const sums = [];
         this.cols.forEach((column, index) => {
            sums[index]="";
        });
        
        sums[7]= "人数:"+linq.from(list).distinct("$.GH").count();
        sums[8]= "在编："+linq.from(list).where("$.XZ_SFZB=='是'").count();
        sums[9]= "女："+linq.from(list).where("$.XZ_XB=='女'").count();
        sums[11]= "少数名族："+linq.from(list).where("$.XZ_MZ !='汉族'").count();
        sums[12]= "大学或以上："+linq.from(list).where("$.XZ_XL !='专科'&& $.XZ_XL !='专科以下'").count();
        sums[13]= "学位："+linq.from(list).where("$.XZ_XW =='学士' || $.XZ_XW=='硕士' || $.XZ_XW=='博士'").count();
        sums[15]= "中级或以上:"+linq.from(list).where("$.XZ_ZYJSZW_DJ =='高级' || $.XZ_ZYJSZW_DJ=='中级'").count();
        sums[17]= "具有专业技术职务："+linq.from(list).count("$.ZYJSZW_FZDW");
        sums[22]= "横向课题："+linq.from(list).where("$.XZ_SFHXKT=='是'").count();
        sums[28]= "成果数量:"+linq.from(list).sum("$.JYCG_SL");
        return sums;
        },
     onDlgCreated(model) {
    
      // var dd = findComponent(this,"BMMC");
      // var 专业 = linq.from(this.$root.教师基本情况).distinct("$.BMMC").toArray();
      // dd.$attrs.items = 专业.map(item => {
      //   return { label: item.BMMC, value: item.BMMC};
      // });
      
    },
    //别的页面不用复制此方法
    
    // onChange(model, field, value) {
    //   //
      
    //   if (field == "BMMC") {
    //     var zydm =  linq.from(this.$root.教师基本情况).where(item=>item.BMMC==value).distinct("$.ZYDM").toArray();
    //     var dd = findComponent(this,"ZYMC");
    //     dd.$attrs.items =zydm.map(item => {
    //       return { value: item.ZYMC, label: item.ZYMC,zydm:item.ZYDM };
    //     });
        
    //     model.ZYMC = dd.$attrs.items[0].value;
    //     model.ZYDM = dd.$attrs.items[0].zydm;
    //     //dd.$children[0].setCurrentValue(dd.$attrs.items[0].ZYDM);
    //   }
    //   if(field == "ZYMC"){
        
    //     var zydm =  linq.from(this.$root.教师基本情况).where(item=>item.ZYMC==value).toArray();
    //     //var dd = findComponent(this,"ZYDM");
    //     model.ZYDM = zydm[0].ZYDM;
    //   }
    //   //
    // },
    // onadd(model){
    //   //
    //   if(model.教研成果_数量=="" && (model.教研成果_最高等级 !==""  || model.教研成果_合作情况 !=="")){
    //     return "第一轮评估日期不能为空";
    //   }
    //    if(  model.教研成果_最高等级 ==""  && (model.教研成果_合作情况 !==""||model.教研成果_数量 !=="")){
    //     return "教研成果_最高等级不能为空";
    //   }
    //   if((model.教研成果_数量 !=="" || model.教研成果_最高等级 !=="")  && model.教研成果_合作情况 ==""){
    //     return "教研成果_合作情况";
    //   }
    //   return undefined;
    //   //
    // },
    
    //导入检查方法
     check(array,list) {
     return new Promise(async (resolve,reject)=>{
        //  try{
          var user = getUser();
          var 教工号 = await get教师基本情况(user.XXID,user.CJPC)
          var 在研 = await get教师其他情况F(user.XXID,user.CJPC)
console.log(在研)
             
          //是否已经存在相同
          
          var err =  linq.from(array).select("$.GH + '' ").except(linq.from(教工号).select("$.GH + '' ").toArray()).toArray();
          linq.from(array).where(e=>err.indexOf(e.GH) !==-1).forEach(e=>e.error=e.error?e.error+";":''+"教师基本情况表不存在对应的教工号");
          //把错误的教师姓名替代掉
          err =  linq.from(array).select("$.GH").intersect(linq.from(教工号).select("$.GH").toArray()).toArray();
          linq.from(array).where(e=>err.indexOf(e.GH) !==-1).
          forEach(e=>{
            var d = linq.from(教工号).firstOrDefault(item=>item.GH == e.GH);
           
            var d2 = linq.from(在研).firstOrDefault(item=>item.GH == e.GH);
           
             if(d){
              e.XM = d.XM;
              e.XZ_XB = d.XZ_XB;
              e.CSRQ = d.CSRQ;    
              e.XZ_MZ = d.XZ_MZ;
              e.XZ_XL = d.XZ_XL;
              e.XZ_XW = d.XZ_XW;
              e.XZ_ZYJSZW_DJ = d.XZ_ZYJSZW_DJ;
              e.ZYJSZW_MC = d.ZYJSZW_MC;
              e.ZYJSZW_FZDW = d.ZYJSZW_FZDW;
              e.ZYJSZW_HQRQ = d.ZYJSZW_HQRQ;
              e.XZ_ZYLY = d.XZ_ZYLY;
              e.XZ_ZYKT_KTXZ = d.XZ_ZYKT_KTXZ;
              e.XZ_KTFL = d.XZ_KTFL;
              e.ZYKT_KTMC = d.ZYKT_KTMC;
              e.XZ_SFHXKT = d.XZ_SFHXKT;
              e.ZYKT_LXRQ = d.ZYKT_LXRQ;
              e.ZYKT_JFLY = d.ZYKT_JFLY;
              e.ZYKT_DKJE = d.ZYKT_DKJE;
              e.XZ_ZYKT_WCRSX = d.XZ_ZYKT_WCRSX;
              e.XZ_ZYKT_KTJB = d.XZ_ZYKT_KTJB;
           }
         
          });
            resolve();
          // }catch(e){
          //   reject(e);
          // }
     }) 
    },
    async  onChange(model, field, value) {
      console.log(model)
       if(field == "GH"){
         if(value == "error"){
           console.log("error")
         
          model.GH="";
          model.XM= "";
          model.XZ_XB="";
          model.CSRQ="";
          model.XZ_MZ="";
          model.XZ_XL="";
          model.XZ_XW="";
          model.XZ_ZYLY="";
          model.XZ_ZYJSZW_DJ = "";
          model.ZYJSZW_MC ="";
          model.ZYJSZW_FZDW="";
          model.ZYJSZW_HQRQ="";
          model.XZ_ZYKT_KTXZ="";
          model.XZ_KTFL="";
          model.ZYKT_KTMC="";
          model.XZ_ZYKT_KTJB="";
          model.ZYKT_LXRQ="";
          model.ZYKT_JFLY="";
          model.ZYKT_DKJE="";
          model.XZ_ZYKT_WCRSX="";
         }else{
         var d1 =  await get教师基本情况ByGH(this.$root.user.XXID,this.$root.user.CJPC,value);
         var d2 = await get教师其他情况FByGH(this.$root.user.XXID,this.$root.user.CJPC,value);
          model.XM= d1[0].XM;
          model.XZ_XB=d1[0].XZ_XB;
          model.CSRQ=d1[0].CSRQ;
          model.XZ_MZ=d1[0].XZ_MZ;
          model.XZ_XL=d1[0].XZ_XL;
          model.XZ_XW=d1[0].XZ_XW;
          model.XZ_ZYLY=d1[0].XZ_ZYLY;
          model.XZ_ZYJSZW_DJ = d1[0].XZ_ZYJSZW_DJ;
          model.ZYJSZW_MC = d1[0].ZYJSZW_MC;
          model.ZYJSZW_FZDW = d1[0].ZYJSZW_FZDW;
          model.ZYJSZW_HQRQ = d1[0].ZYJSZW_HQRQ;
          model.XZ_ZYKT_KTXZ = d2[0].XZ_ZYKT_KTXZ;
          model.XZ_KTFL = d2[0].XZ_KTFL;
          model.ZYKT_KTMC = d2[0].ZYKT_KTMC;
          model.XZ_SFHXKT = d2[0].XZ_SFHXKT;
         
          model.ZYKT_LXRQ = d2[0].ZYKT_LXRQ;
          model.ZYKT_JFLY = d2[0].ZYKT_JFLY;
          model.ZYKT_DKJE = d2[0].ZYKT_DKJE;
          model.XZ_ZYKT_WCRSX = d2[0].XZ_ZYKT_WCRSX;
           model.XZ_ZYKT_KTJB = d2[0].XZ_ZYKT_KTJB;
        console.log("kong:"+d2[0].XZ_ZYKT_KTJB)

       
         }
       }

      //
    },

    async fetchData() {
      var user = getUser();
      var datas = await getJxyjjbqk(user.XXID,user.CJPC);
      return datas;
    },
      add_check(model,list){
      //
         //是否已经存在数据
          var first =  linq.from(list).firstOrDefault(e=>e.GH ==  model.GH);
         
          if(first)
          return "已经存在对应教工号"
      //
    },
     onadd(model) {
      //
      var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
           
           try{
        
          console.log(JSON.stringify(temp));
          var model = await addJxyjjbqk(temp);
          resolve(model);
          }catch(e){
             reject(e);
           }
      })
      
    },
    async  bulkAdd(array){
       await  bulkAddJxyjjbqk({Jxyjjbqk:array});
    },
    onupdate(model) {
      //
      var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
           
          console.log(JSON.stringify(temp));
          var model = await updateJxyjjbqk(temp);
          resolve(model);
      })
      //
    },
    ondelete(model) {
       var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
        
         await deleteJxyjjbqk(temp);
          resolve();
      })
    }
  }
};
</script>
<style>
</style>